{extend name="lib/common_list" /}
{block name="title"}{/block}
{block name="css"}
{load href="/static/sys/css/common.css" /}
{load href="/static/plugins/select2/css/select2.css" /}
{load href="/static/plugins/bootstrap-datetimepicker/css/bootstrap-datetimepicker.css" /}

{load href="/static/sys/css/skin_0.css" /}
<style>
    .upfile i{padding-right:3px !important;}
    .file{ position:absolute;right:0;top:0;width:100px;height:100px;opacity:0; ilter:alpha(opacity=0);cursor:pointer;margin-bottom: 0px;margin-right: 0px; }
</style>
{/block}
{block name="javascript"}
{load  href="/static/plugins/select2/js/select2.js" /}
{load  href="/static/plugins/bootstrap-datetimepicker/js/bootstrap-datetimepicker.js" /}
{load  href="/static/plugins/bootstrap-datetimepicker/js/locales/bootstrap-datetimepicker.zh-CN.js" /}

<script>
    $(document).ready(function () {
        $("#ok").bind("click", save);
        $("#cancel").bind("click", function () {
            parent.layer.close(parent.layer_edit_index);
        });
        // 选择图片
        $("#avatar_img").bind("click", chooseImg);

        /**
         * 保存内容
         */
        function save() {
            var load_index = layer.load(0, { shade: false });
            $.ajax({
                type: 'POST',
                url: "{:url('wechat/edit')}",
                data: $("#fmNew").serialize(),
                dataType: 'json',
                success: function (data) {
                    if (data.code == 1) {
                        layer.close(load_index);
                        layer.alert(data.msg, function () {
                            parent.refreshtb();
                            parent.layer.close(parent.layer_edit_index);
                        });
                    } else {
                        layer.alert(data.msg);
                    }
                }
            })
        }

        var layer_chose_index;
        function chooseImg() {
            layer_chose_index = layer.open({
                type: 2,
                title: "选择头像",
                area: ['100%', '100%'],
                content: "{:url('selection/image')}?category=" + "{$category}",
            })
        }

        // 小程序下拉list
        $('#applet_name').select2();
    });

    // 跨域选中图片后的回调函数
    function get_selected_img(res) {
        $('#avatar').val(res.image_url);
        $('#previewImg_avatar').attr('src', res.image_url);
    }

    function appletValue() {
        var applet_id = $("#applet_name").children('option:selected').attr('applet_id');
        var original_id = $("#applet_name").children('option:selected').attr('original_id');
        $('#applet_id').val(applet_id);
        $('#original_id').val(original_id);
        $('#applet_onchange').show();
    }

</script>
{/block}

{block name="content"}
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-content">
                    <form method="post" id="fmNew" class="form-horizontal" enctype="multipart/form-data">

                        <div class="form-group">
                            <label class="col-sm-2 control-label">小程序：</label>
                            <div class="col-sm-8">
                                <select class="form-control" name="applet_name" id="applet_name" onchange="appletValue();">
                                    <option value="">请选择小程序.....</option>
                                    {volist name="applet_list" id="v"}
                                    <option value="{$v.name}" applet_id ="{$v.id}" original_id="{$v.original_id}" {if($v.id==$Rs.applet_id)} selected{/if}>{$v.name}</option>
                                    {/volist}
                                </select>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>

                        <div class="form-group" style="display: none" id="applet_onchange">
                            <label class="col-sm-2 control-label">原始ID：</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" name="original_id"  value="{$Rs.original_id}" id="original_id" readonly>
                                <input type="hidden" class="form-control" name="applet_id" value="{$Rs.applet_id}" id="applet_id">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">微信昵称：</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" name="nick_name" value="{$Rs.nick_name}" placeholder="请输入昵称">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">open id：</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" name="openid"  value="{$Rs.openid}" placeholder="open id">
                            </div>
                        </div>

                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">用户头像：</label>

                            <div class="col-sm-1">
                                <span id="avatar_img" class="btn btn-primary btn-sm" style="margin-bottom:0;padding:6px 8px;">
                                    <i class="glyphicon glyphicon-folder-open" style="padding-right:3px;"></i> 头像<input type="hidden" name="avatar_url" value="{$Rs.avatar_url}" id="avatar" />
                                </span>
                            </div>
                            <div class="col-sm-1">
                                <img id="previewImg_avatar" style="height:34px;float: right;" src="{$Rs.avatar_url}">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">性别：</label>
                            <div class="col-sm-8">
                                <select class="form-control" name="gender" id="gender">
                                    {volist name="gender_list" id="v"}
                                    <option value="{$key}" {if ($key==$Rs.gender)>{$v}</option>
                                    {/volist}
                                </select>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">剩余抽卡机会：</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" name="remainder" value="{$Rs.remainder}" placeholder="剩余抽卡机会">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">红包金额：</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" name="award" value="{$Rs.award}" placeholder="兑换的红包总额">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">语言：</label>
                            <div class="col-sm-8">
                                <select class="form-control" name="language" id="language">
                                    {volist name="language_list" id="v"}
                                    <option value="{$key}" {if($key== $Rs.language)} selected {/if}>{$v}</option>
                                    {/volist}
                                </select>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">用户状态：</label>
                            <div class="col-sm-8">
                                <select class="form-control" name="status" id="status">
                                    {volist name="status_list" id="v"}
                                    <option value="{$key}" {if($key==$Rs.status)}selected {/if}>{$v}</option>
                                    {/volist}
                                </select>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">国家：</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" name="country" value="{$Rs.country}" placeholder="所在国家">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">省份：</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" name="province" value="{$Rs.province}" placeholder="所在省份">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">城市：</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" name="city" value="{$Rs.city}" placeholder="所在城市">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>

                        <div id = 'hidden_input'>
                            <input id="type" type="hidden" name='type' value="{$Rs.type}"/>
                            <input id="id" type="hidden" name='id' value="{$Rs.id}"/>
                        </div>

                        <div class="form-group">
                            <div class="col-sm-12 col-sm-offset-5">
                                <button class="btn btn-primary" id="ok" type="button">提交</button>
                                <button class="btn btn-white" id="cancel" type="button">取消</button>
                            </div>
                        </div>

                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
{/block}